<template>
  <view class="indexRecommend" :style="[outModuleCss]">
    <view :style="[moduleBgCss]" class="module-bg"></view>
    <view class="recommendContent">
      <view class="title" v-if="propsData.params.useTitle == 1">
        <moduleHeader
          :propsData="propsData"
          :moduleName="moduleName"
        ></moduleHeader>
      </view>
      <view class="recommendList">
        <template v-for="(item, index) in propsData.params.list">
          <view
            class="recommendItem"
            :key="index"
            v-if="index < propsData.params.line * 2"
            @click.stop="$utils.diySkip(item.pics.link)"
          >
            <view class="recommendHead">
              <view class="name">
                <view :style="[fontCss(item.title.css)]" class="nameTitle">
                  {{ item.title.useTitle == 1 ? item.title.text : "" }}
                </view>
                <countDown
                  v-if="item.type.style == 1"
                  :propsData="item.type"
                ></countDown>
                <image
                  :src="item.type.picUrl"
                  alt=""
                  lazy-load
                  class="tip"
                  mode="heightFix"
                  v-if="item.type.style == 2"
                />
              </view>
              <text
                class="subName"
                :style="[fontCss(item.subTitle.css)]"
                v-if="item.subTitle.useTitle == 1"
              >
                {{ item.subTitle.text }}
              </text>
            </view>
            <view class="recommendPics">
              <view
                class="picItem1"
                v-for="(pic, picIndex) in item.pics.urls"
                :key="picIndex"
                @click.stop="
                  handle('goLink', {
                    link: item.pics.link,
                    index: picIndex,
                  })
                "
              >
                <image :src="pic.picUrl" alt="" lazy-load mode="aspectFill" />
              </view>
              <view
                class="picItem"
                v-for="item in 2 - item.pics.urls.length"
                :key="item"
              ></view>
            </view>
          </view>
        </template>
      </view>
    </view>
  </view>
</template>

<script>
import { diyMixin } from "../mixins/diy";
import countDown from "../components/countDown.vue";
import moduleHeader from "../components/moduleHeader/index.vue";
export default {
  components: {
    countDown,
    moduleHeader,
  },
  name: "indexRecommend",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
  },
  mixins: [diyMixin],

  computed: {
    moduleName() {
      return this.propsData.params.text;
    },
  },
  methods: {
    handle(type, params) {
      switch (type) {
        case "goLink":
          if (params.link[params.index]) {
            this.$utils.diySkip(params.link[params.index]);
          } else {
            this.$utils.toast("链接无效");
          }
          break;
      }
    },

    // 预览图片
    previewImg(list, index) {
      let pics = [];
      list.forEach((item) => {
        pics.push(item.picUrl);
      });
      uni.previewImage({
        current: index,
        urls: pics,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.indexRecommend {
  position: relative;
  .recommendContent {
    width: 100%;
    padding: 24rpx 24rpx 0 24rpx;
  }
  .module-bg {
    width: 100%;
    height: 100%;
    z-index: -1;
    position: absolute;
    left: 0;
    top: 0;
  }
  .title {
    width: 100%;
    margin-bottom: 24rpx;
    .name {
      font-size: 32rpx;
      font-weight: 600;
    }
    .more {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #888;
      i {
        font-size: 20rpx;
      }
    }
  }
  .recommendList {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .recommendItem {
      margin-bottom: 24rpx;
      width: 49%;
      .recommendHead {
        .name {
          display: flex;
          align-items: center;
          .nameTitle {
            min-width: 120rpx;
            min-height: 46rpx;
            font-size: 32rpx;
          }
          .countDown {
            margin-left: 16rpx;
            display: flex;
            align-items: center;
            font-size: 20rpx;
            font-weight: 600;
            text:nth-child(2n + 1) {
              width: 30rpx;
              height: 30rpx;
              background-color: #fc402f;
              border-radius: 6rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              color: #fff;
            }
            text:nth-child(2n) {
              color: #fc402f;
              margin: 0 6rpx;
            }
          }
          .tip {
            min-width: 80rpx;
            height: 34rpx;
            margin-left: 16rpx;
          }
        }
        .subName {
          display: inline-block;
          font-size: 24rpx;
        }
      }
      .recommendPics {
        height: 160rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .picItem1 {
          width: 49%;
          height: 160rpx;
          overflow: hidden;
          border-radius: 10rpx;
          image {
            width: 100%;
            height: 100%;
          }
        }
        .picItem {
          width: 168rpx;
          height: 160rpx;
          background-color: #f2f2f2;
          overflow: hidden;
          border-radius: 10rpx;
        }
      }
    }
  }
}
</style>
